package com.qzdatasoft.ratelimit.adapter.impl;

import com.qzdatasoft.ratelimit.adapter.RateLimitRuleQueryProvider;
import com.qzdatasoft.ratelimit.po.RateLimitRulePo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * 默认限流规则查询提供者实现 从配置文件加载
 */
public class DefaultRateLimitRuleQueryProvider implements RateLimitRuleQueryProvider {
    private static final Logger logger = LoggerFactory.getLogger(DefaultRateLimitRuleQueryProvider.class);
    private final List<RateLimitRulePo> yamlBusinessRules;

    public DefaultRateLimitRuleQueryProvider(List<RateLimitRulePo> businessRules) {
        this.yamlBusinessRules = (null == businessRules) ? new ArrayList<>() : businessRules;
        logger.info("从配置属性加载了 {} 个启用的限流规则", yamlBusinessRules.size());
    }

    @Override
    public List<RateLimitRulePo> loadEnabledRules() {
        List<RateLimitRulePo> enabledRules = new ArrayList<>();
        enabledRules.addAll(this.yamlBusinessRules);
        return enabledRules;
    }

}